package com.jz.netthings.security.browser.handler;

import com.jz.netthings.support.SecurityConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author yyy
 * @ClassName AdscmUrlAccessDeniedHandler
 * @Description 没有权限的处理
 * @date 2018/7/27 0:20
 */
@Component("adscmUrlAccessDeniedHandler")
public class AdscmUrlAccessDeniedHandler implements AccessDeniedHandler {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {
        logger.info("没有权限访问资源，统一跳转到请求："+ SecurityConstants.DEFAULT_ACCESS_DENIED_URL);
//        httpServletResponse.sendRedirect(SecurityConstants.DEFAULT_ACCESS_DENIED_URL);
        httpServletRequest.getRequestDispatcher(SecurityConstants.DEFAULT_ACCESS_DENIED_URL).forward(httpServletRequest,httpServletResponse);

    }


}
